package com.wc.AlgoOJ_train.train2_DP训练.c1.DP0003;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/11 22:20
 * @description 最长上升子序列
 * http://43.138.190.70:8888/p/DP0003
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int[] arr = new int[n];
        int[] dpl = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        // O(n^2)
//        for (int i = 0; i < n; i++) {
//            dpl[i] = 1;
//            for (int j = i + 1; j < n; j++) {
//                if (arr[i] < arr[j]) {
//                    dpl[j] = Math.max(dpl[i] + 1, dpl[j]);
//                }
//            }
//        }

//        int ans = 0;
//        for (int i = 0; i < n; i++) {
//            ans = Math.max(ans, dpl[i]);
//        }
        dpl[0] = arr[0];
        int len = 0;
        for (int i = 1; i < n; i++) {
            if (arr[i] > dpl[len]) {
                dpl[++len] = arr[i];
            } else {
                int l = 0;
                int r = len;
                while (l <= r) {
                    int mid = l + (r - l) / 2;
                    if (dpl[mid] >= arr[i]) {
                        r = mid - 1;
                    } else {
                        l = mid + 1;
                    }
                }
                dpl[l] = arr[i];
            }
        }
        out.println(len + 1);
        out.flush();
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }
}